
#ifndef _CTHREAD_READ_WRITE_MUTEX_H_
#define _CTHREAD_READ_WRITE_MUTEX_H_ 

#include <assert.h>
#include <pthread.h>

namespace CThread
{

class ReadWriteMutex 
{
public:
	ReadWriteMutex();
	~ReadWriteMutex();

	// these get the lock and block until it is done successfully
	void acquireRead();
	void acquireWrite();

	// these attempt to get the lock, returning false immediately if they fail
	bool attemptRead();
	bool attemptWrite();

	// this releases both read and write locks
	void release();
	
private:
	pthread_rwlock_t rw_lock_;
};

};

#endif // #ifndef _CTHREAD_READ_WRITE_MUTEX_H_
